//
//  FeedbackViewController.m
//  JinYong_iOS_Store
//
//  Created by 王厚一 on 2017/10/22.
//  Copyright © 2017年 why. All rights reserved.
//


#import "FeedbackViewController.h"

@interface FeedbackViewController ()<UITextViewDelegate>

@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) UILabel *placeholderLab;


@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(245, 245, 245);
    [self setupNavigationItem];
    [self creatUI];

}
-(void)setupNavigationItem{
    
    UIView * topView = ({
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(ActualW(0), ActualH(0), ActualW(375), ActualH(64))];
        CAGradientLayer * gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = view.bounds;
        //设置渐变区域的起始和终止位置（范围为0-1）
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        //设置颜色数组
        gradientLayer.colors = @[(__bridge id)RGB(22, 125, 255).CGColor, (__bridge id)RGB(0, 178, 255).CGColor];
        //设置颜色分割点（范围：0-1）
        gradientLayer.locations = @[@(0.0f), @(1.0f)];
        [view.layer addSublayer:gradientLayer];
        view;
    });
    [self.view addSubview:topView];
    
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ActualW(10), ActualH(31.5), ActualW(18), ActualH(18))];
    imageView.image = [UIImage imageNamed:@"back"];
    [topView addSubview:imageView];
    
    
    UIButton * backButton = [[UIButton alloc] initWithFrame:CGRectMake(ActualW(0), ActualH(13.5), ActualW(41), ActualH(44))];
    [backButton addTarget:self action:@selector(popAction) forControlEvents:UIControlEventTouchUpInside];
    
    [topView addSubview:backButton];
    
    UILabel * title = ({
        UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(ActualW(152.5), ActualH(32), ActualW(72), ActualH(17))];
        label.textColor = RGB(255, 255, 255);
        label.textAlignment = NSTextAlignmentLeft;
        label.text = @"意见反馈";
        label.font = FontX(FONTSIZE(17));
        label;
    });
    [topView addSubview:title];
    
    
}

-(void)creatUI{
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(ActualW(10), ActualH(85), ActualW(355), ActualH(235))]; //初始化大小并自动释放
    
    self.textView.textColor = [UIColor blackColor];//设置textview里面的字体颜色
    
    self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];//设置字体名字和字体大小
    
    self.textView.delegate = self;//设置它的委托方法
    
    self.textView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色
    
    self.textView.returnKeyType = UIReturnKeyDefault;//返回键的类型
    
    self.textView.keyboardType = UIKeyboardTypeDefault;//键盘类型
    
    self.textView.scrollEnabled = YES;//是否可以拖动
    
    self.textView.textColor = RGB(51, 51, 51);
    
    self.textView.font = FontX(FONTSIZE(13));
    
    self.textView.text = @"请描述一下您的问题";
    
    self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度
    
    
    [self.view addSubview: self.textView];//加入到整个页

    
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(ActualW(30), ActualH(320), ActualW(315), ActualH(40))];
    button.titleLabel.font = FontX(FONTSIZE(18));
    [button setTitle:@"确认提交" forState:UIControlStateNormal];
    [button setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    button.backgroundColor = RGB(64, 137, 248);
    button.layer.cornerRadius = ActualW(4);
    [button addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [self.view addSubview:button];
    
    
    
}



-(void)submitAction {
    
//    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    
//    [dict addEntriesFromDictionary:@{@"ctl":@"Feed",@"met":@"addFeed",@"typ":@"json",@"feed_desc":_textView.text, @"k":RESULT_USERINFO_k,@"u":RESULT_USERINFO_u}];
//    
//    [AFTool postWithURL:Base_URL params:dict success:^(NSDictionary *result) {
//        
//        [MBProgressHUD showSuccess:@"提交成功"];
//        [self.navigationController popViewControllerAnimated:YES];
//
//        
////        [MBProgressHUD hideHUD];
////
////        if ([Pub resultSuccess:result]) {
////            [MBProgressHUD showSuccess:@"提交成功"];
////        }
////        [MBProgressHUD hideHUD];
//        
//        
//    } failure:^(NSError *error) {
//        [MBProgressHUD hideHUD];
//
//    }];
//    
//    
}

- (void)textViewDidBeginEditing:(UITextView *)textView { //设置textView的placeHolder
    if ([textView.text isEqualToString:@"请描述一下您的问题"]) {
        textView.textColor = RGB(51, 51, 51);
        textView.text = @"";
    }
    
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    
    if (textView.text.length<1) {
        textView.textColor = RGB(153, 153, 153);
        textView.text = @"请描述一下您的问题";
    }
    
}

- (void)popAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
